import { defineConfig, ConfigEnv } from "vite";
import { resolve } from "path";
import uni from "@dcloudio/vite-plugin-uni";
// https://vitejs.dev/config/
const pathResolve = (dir: string) => {
  return resolve(__dirname, ".", dir);
};
const alias: Record<string, string> = {
  "/static": pathResolve("./src/static"),
};
const viteConfig = defineConfig(async (mode: ConfigEnv) => {
  const UnoCss = await import("unocss/vite").then((i) => i.default);
  return {
    plugins: [uni(), UnoCss()],
    root: process.cwd(),
    resolve: {
      alias,
    },
    build: {
      rollupOptions: {
        input: {
          "public/amap/mapWx": "./src/public/amap/mapWx.js",
          "public/amap/qqmap-wx-jssdk": "./src/public/amap/qqmap-wx-jssdk.js",
          "public/amap/qqmap-wx-jssdk.min": "./src/public/amap/qqmap-wx-jssdk.min.js",
        },
      },
    },
    extensions: [
      ".mjs",
      ".js",
      ".ts",
      ".jsx",
      ".tsx",
      ".json",
      ".min.js",
      ".jsx",
    ],
    base: mode.mode == "development" ? "/" : "/h5/",
    server: {
      host: true,
      port: 3366,
      cors: true,
      hmr: true,
      open: true,
    },
  };
});
export default viteConfig;
